<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/14
 * Time: 16:14
 */

namespace app\admin\controller;

use app\admin\model\Collage as CollageModel;
use app\admin\model\Goods as GoodsModel;

class CollageController extends BaseController
{
    public function index()
    {
        $this->assign([
            'lists' => CollageModel::order(['id'=>'asc'])->paginate(15,false,['type'=>'page\Page']),
        ]);
        return $this->fetch();
    }

    public function add()
    {
        if($this->request->isPost()){
            $params = $this->request->param();
            $model = new CollageModel();
            if($model->allowField(true)->isUpdate(false)->save($params)){
                return ['error'=>0,'msg'=>'拼团活动添加成功!'];
            }else{
                return ['error'=>1,'msg'=>'拼团活动添加失败!'];
            }
        }
        $this->assign([
           'goods'=>GoodsModel::order(['id'=>'asc'])->select(),
        ]);
        return $this->fetch();
    }

    public function edi()
    {
        $params = $this->request->param();
        if($this->request->isPost()){

        }
        $this->assign([
            'goods'=>GoodsModel::order(['id'=>'asc'])->select(),
            'data' => CollageModel::where(['id'=>$params['id']])->find(),
        ]);
        return $this->fetch();
    }

    public function del()
    {
        $id = $this->request->param('id');
        if(CollageModel::where(['id'=>$id])->delete()){
            return ['error'=>0,'msg'=>'拼团活动删除成功!'];
        }else{
            return ['error'=>1,'msg'=>'拼团活动删除失败!'];
        }
    }
}